package com.dji.sdk.extensions.java.util.Optional;

import manifold.ext.rt.api.Extension;
import manifold.ext.rt.api.This;

import java.util.NoSuchElementException;
import java.util.Optional;

/**
 * @author 吴昊
 */
@Extension
public class OptionalExtension {
    public static <T> boolean isEmpty(@This Optional<T> value) {
        return value == null || !value.isPresent();
    }

    public static <T> T orElseThrow(@This Optional<T> value) {
        return value.orElseThrow(() -> new NoSuchElementException("No value present"));
    }
}
